import jwt
import datetime
#载荷中加入上面周期的概念
playload = {
    #过期时间
    'exp':int((datetime.datetime.now() + datetime.timedelta(seconds=120)).timestamp()),
    'data':{'uid':2}
}
#生成jwt
encode_jwt = jwt.encode(playload,'qwe123',algorithm='HS256')
#转码
encode_str = str(encode_jwt,'utf-8')
#解密
try:
    encode_jwt = jwt.decode(encode_str,'qwe123',algorithms=['HS256'])
except Exception as e:
    print('该密钥已过期')
    pass
print(encode_str)
print(encode_jwt)
